﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace MyProject.Tools
{
    public partial class SoapTester : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_SendRequest_Click(object sender, EventArgs e)
        {
            this.txtbx_Response.Text = "";
            try
            {
                string url = this.txtbx_url.Text.Trim();
                string request = this.txtbx_Request.Text.Trim();
                HttpWebRequest m_Request = (HttpWebRequest)WebRequest.Create(url);
                //相应请求的参数
                byte[] data = Encoding.GetEncoding("UTF-8").GetBytes(request);
                m_Request.Method = "POST";
                m_Request.ContentType = "text/xml";
                m_Request.ContentLength = data.Length;
                m_Request.Timeout = 10000;
                //请求流
                Stream requestStream = m_Request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
                //响应流
                HttpWebResponse m_Response = (HttpWebResponse)m_Request.GetResponse();
                Stream responseStream = m_Response.GetResponseStream();
                StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"));
                //获取返回的信息
                string result = streamReader.ReadToEnd();
                streamReader.Close();
                responseStream.Close();
                this.txtbx_Response.Text = result;
            }
            catch (Exception ex)
            {
                this.txtbx_Response.Text = ex.Message;
            }
        }


    }
}